// 代理对象 Proxy

const person = {
    name: 'zce',
    age: 20
}

const personProxy = new Proxy(person, {
    get (target, property) {
        return property in target ? target[property] : 'default'
    },
    set(target, property, value) {
        if(property === 'age') {
            if(!Number.isInteger(value)){
                throw new TypeError(`${value} is not an int`)
            }
        }
        target[property] = value
        // console.log(target, property, value)
    }
})

// 触发 get
// console.log(personProxy.name)
// console.log(personProxy.xxx)

// 触发 set
personProxy.gender = true
personProxy.age = 12